/* Author	: Manish YM
 * Date		: 30/07/2009
 * Description	: Explains how to run user mode commands and programs from kernel using kernel functions. Taken from chapter 3 of Essential Device Drivers book.
 */

/* Its simple, run call_usermodehelper which is similar to execv system call. Only thing to keep in mind is to put usermode helper name
 * and path in /sys folder. 
 */

static void run_umode_handler ( int myevent_id )
{
    int i = 0 ;
    char *argv[2], *envp[4], *buffer=NULL ;
    int value ;

    argv[i++] = myevent_handler ;
    /*
     * Has to be defined in /sys/ folder for this perticular module. 
     * It will be taken from /sys by kernel.
     */
    if (!argv[0])
	return ;
    argv[i] = NULL ;
    i = 0;
    envp[i++] = "HOME=/" ;
    envp[i++] = "PATH=/sbin:/usr/sbin:/bin:/usr/bin"
    envp[i++] = buffer ;
    /*FILL buffer before this by giving approprite data*/
    envp[i] = NULL ;

    value = call_usermodehelper (argv[0], argv, envp, NULL) ;
    kfree (buffer) ;
    return ;
}



/***********************************************************************************************************
 * For sysctl to create a entry in /sys filesystem it is required that we add an entry in 
 * include/linux/sysctl.h. 
 * then we have to put the path in /proc/sys/kernel/myevent_handler
 ***********************************************************************************************************/

{
	.ctl_name = KERN_MYEVENT_HANDLER, 
	.procname = "myevent_handler",
	.data = &myevent_handler,
	.maxlen = 256;
	.mode = 0644 ;
	.proc_handler = &proc_dostring ;
	.strategy = &sysctl_string ;
}
